<?php
/**
 * Created by PhpStorm.
 * User: yuanluke
 * Date: 5/4/16
 * Time: 15:05
 */

namespace App\Http\Utils\Common;


use App\Http\Model\UserPtDict;

class DictUtils {

    public static function getDict($name,$search)
    {
        $params = [];
        $dict = UserPtDict::select('text','value')->where('cate',$search)->get();
        $params[$name] = $dict;
        return $params;
    }


    //根据参数获取字典表的数据
    public static function getDictMsg(array $params){
        try {
            $result=array();
            if(!empty($params)){
                foreach ($params as $key=>$val){
                    $dictList=UserPtDict::where('cate',$val)->get();
                    if(!empty($dictList)){
                        $item=array();
                        foreach ($dictList as $d){
                            $i['text']=$d->text;
                            $i['value']=$d->value;
                            $item[]=$i;
                        }
                    }
                    $result[$key]=$item;
                }
            }
            return $result;
        }catch (Exception $ex) {
            throw $ex;
        }
    }

}